package com.spyx.controller;

import com.atyx.spyx.model.search.SkuEs;
import com.atyx.spyx.vo.search.SkuEsQueryVo;
import com.spyx.result.Result;
import com.spyx.service.ProductSearchService;
import com.spyx.service.SkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/search/sku")
public class SkuController {
    @Autowired
    private ProductSearchService productSearchService;

    //分类模块中，查询某个分类下的商品信息 (同时有模糊查)
    // http://localhost:xxx/api/search/product/{pagenum}/{limit}
    @GetMapping("/{pagenum}/{limit}")
    public Result getskuinfo(
            @PathVariable("pagenum") Integer pageNum,
            @PathVariable("limit") Integer limit,
            SkuEsQueryVo queryVo){
        PageRequest pageRequest = PageRequest.of(pageNum - 1, limit);//开始位置0开始
        Page<SkuEs> pageModel= productSearchService.search(pageRequest,queryVo);

        return Result.ok(pageModel);
    }

    @Autowired
    private SkuService skuService;

    //更新点击量 -Skues中的hotscore字段
    @GetMapping("inner/incrHotScore/{skuId}")
    public Boolean incrHotScore(@PathVariable("skuId") Long skuId) {
        // 调用服务层
        skuService.incrHotScore(skuId);
        return true;
    }


}
